import django_filters
from main.filters import NumberInFilter
from main.models import MeasureSheet
from main.permissions import DjangoModelFullPermissions
from rest_framework import serializers, viewsets


class MeasureSheetSerializer(serializers.ModelSerializer):
    creator = serializers.PrimaryKeyRelatedField(read_only=True, required=False)
    worker = serializers.PrimaryKeyRelatedField(read_only=True, required=False)
    request = serializers.PrimaryKeyRelatedField(read_only=True, required=False)
    order = serializers.PrimaryKeyRelatedField(read_only=True, required=False)

    class Meta:
        model = MeasureSheet
        fields = (
            "id",
            "date",
            "address",
            "status",
            "data",
            "note",
            "created_on",
            "updated_on",
            "request",
            "order",
            "worker",
        )


class MeasureSheetFilter(django_filters.FilterSet):
    ids = NumberInFilter(field_name="id", lookup_expr="in")

    class Meta:
        model = MeasureSheet
        fields = ("id",)


class MeasureSheetViewSet(viewsets.ModelViewSet):
    queryset = MeasureSheet.objects.all()
    serializer_class = MeasureSheetSerializer
    permission_classes = (DjangoModelFullPermissions,)
    filterset_class = MeasureSheetFilter
